package com.huge.simple.common.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;

/**
 * @author jihu
 * date 2022-03-28
 */
@ApiModel(value="接口返回对象", description="接口返回对象")
public class Result<T> implements Serializable {

    @ApiModelProperty(value = "接口成功状态")
    private Boolean success;

    @ApiModelProperty("http返回状态码")
    private HttpCode code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private T result;


    public static <T> Result<T> success(String message){
        return new Result<T>()
                .setSuccess(Boolean.TRUE)
                .setCode(HttpCode.SUCCESS)
                .setMessage(message);
    }

    public static <T> Result<T> success(T data){
        return new Result<T>()
                .setSuccess(Boolean.TRUE)
                .setCode(HttpCode.SUCCESS)
                .setMessage("操作成功")
                .setResult(data);
    }

    public static <T> Result<T> success(String message,T data){
        return new Result<T>()
                .setSuccess(Boolean.TRUE)
                .setCode(HttpCode.SUCCESS)
                .setMessage(message)
                .setResult(data);
    }

    public static <T> Result<T> success(HttpCode code,String message,T data){
        return new Result<T>()
                .setSuccess(Boolean.TRUE)
                .setCode(code)
                .setMessage(message)
                .setResult(data);
    }

    public static <T> Result<T> error(String message){
        return new Result<T>()
                .setSuccess(Boolean.FALSE)
                .setCode(HttpCode.ERROR)
                .setMessage(message);
    }


    public Boolean getSuccess() {
        return success;
    }

    public Result<T> setSuccess(Boolean success) {
        this.success = success;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Result<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getResult() {
        return result;
    }

    public Result<T> setResult(T result) {
        this.result = result;
        return this;
    }

    public HttpCode getCode() {
        return code;
    }

    public Result<T> setCode(HttpCode code) {
        this.code = code;
        return this;
    }
}

